<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">
    
    <ui:define name="head-title">
        <title>Add Sale Quotation | Merlion's ERP System</title>
    </ui:define>    
                  
    <ui:define name="content">
        <f:view beforePhase="#{saleQuotationManagerBean.initView}">
            
            <h:form>
                <p:panel id ="panel" header ="Add New Sale Quotation">
                    <p:ajaxStatus style ="width:16px;height:16px;">
                        <f:facet name ="start">
                            <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif"/>
                        </f:facet>
                        
                        <f:facet name ="complete">
                            <h:outputText value=""/>
                        </f:facet>
                    </p:ajaxStatus>
                    
                    <p:messages />
                    <h:panelGrid columns="3" cellpadding="10"> 
                    
                        <h:outputLabel for="saleLeadName" style="font-weight: bold" value="Company Name:"/>
                        <p:autoComplete value="#{saleQuotationManagerBean.saleLeadName}" required="true" label="Company Name"
                                        requiredMessage="Company Name is required." id="saleLeadName" completeMethod="#{saleQuotationManagerBean.complete}"/>
                        <p:message for="saleLeadName"/>

                        <h:outputLabel for="customDiscount" style="font-weight: bold" value="Customer Discount(%):"/>
                        <p:inputText value="#{saleQuotationManagerBean.customDiscount}" required="true" label="Custom Discount"
                                         requiredMessage="Customer Discount is required." id="customDiscount" />
                        <p:message for="customDiscount"/>
                        
                        <h:outputLabel for="validityPeriod" style="font-weight: bold" value="Validity Period(days):"/>
                        <p:inputText value="#{saleQuotationManagerBean.validityPeriod}" required="true" label="Validity Period"
                                         requiredMessage="Validity Period is required." id="validityPeriod" />
                        <p:message for="validityPeriod"/>

                        <p:spacer height="15"/>
                    </h:panelGrid>
                        <p:dataTable var="lineItem" value="#{saleQuotationManagerBean.lineItems}"
                                 dynamic="true" paginator="true" emptyMessage="No Product Type">
                            <p:column sortBy="#{lineItem.productPrice.productType}">
                                <f:facet name="header">
                                    <h:outputText value="Type"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productType}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Unit Price"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productPrice}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:inputText value="#{lineItem.lineItemQuantity}" />
                            </p:column>

                            <p:column>
                            <f:facet name="header">
                                <h:outputText value="Volume Discount"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.volumeDiscountRate}"/>    
                            </p:column>

                            <p:column>
                            <f:facet name="header">
                                <h:outputText value="Price"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.finalPrice}"/>
                            </p:column>

                            <f:facet name="footer">
                                <h:outputText value="Total Price: "/>
                                <h:outputText value="#{saleQuotationManagerBean.finalPrice}"/>
                            </f:facet>
                        </p:dataTable>

                    
                    <p:commandButton id="btn" value="Save new Sale Quotation" update="panel" actionListener="#{saleQuotationManagerBean.saveSaleQuotation}" ajax="true"/>
                    <p:commandButton value="Refresh Price" update="panel" actionListener="#{saleQuotationManagerBean.calculate}" ajax="true"/>
                </p:panel>
                
            </h:form>
        </f:view>
    </ui:define>

</ui:composition>
